import logging
import requests

logger = logging.getLogger(__name__)


def 库存上传(filepath, filepathname, timestamp):
    for i in range(3):
        try:
            url = 'http://192.168.16.240:8001/api/VerifyOrder/VerifyOrder/ImportInventoryAsync'
            files = {'file': (filepathname, open(filepath, 'rb'))}
            data = {'batchNumber': timestamp}
            res = requests.post(url, files=files, data=data)
            if res.status_code == 200 and 'false' not in res.text:
                # print('上传成功')
                logger.info(res.text)
                logger.info('商品库存上传成功')
            else:
                # print('上传失败')
                logger.info(res.text)
                logger.info('商品库存上传失败')
                raise Exception(res.text)
            break
        except Exception as e:
            print(e)
            continue
